﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MPBlog.DAL;
using NHibernate.Criterion;
using MPBlog.Model;

namespace MPBlog.EasyVS
{
    public partial class AcceptData : System.Web.UI.Page
    {
        SoftwareUseStatisticsDao dao = new SoftwareUseStatisticsDao();

        protected void Page_Load(object sender, EventArgs e)
        {
            string mac =  Request.QueryString["mac"];
            string computerName = Request.QueryString["name"];
            string soft = Request.QueryString["software"];

            if (mac == null || computerName == null || soft == null)
            {
                return;
            }

            int rowId = dao.CheckHasExist(mac, soft);
            if (rowId != -1)
            {

                SoftwareUseStatistics statistics = dao.GetById(rowId);
                statistics.LastUseTime = DateTime.Now;
                statistics.ComputerName = computerName;
                dao.Update(statistics);
            }
            else
            { 
                 SoftwareUseStatistics statistics = new SoftwareUseStatistics{
                    Mac = mac,
                    ComputerName = computerName,
                    CreatedTime = DateTime.Now,
                    LastUseTime = DateTime.Now,
                    SoftwareName = soft
                 };
                //新建记录
                 dao.Create(statistics);
            }
        }
    }
}